﻿/*
 * Copyright © 2011 Tristan Reeves, treeves@gmail.com
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
using System.Text;

namespace Sprinkles.Tests.DeploymentHosts
{
    public class PropertyHost_Untyped : DeploymentHost
    {
        public class Test
        {
            public object P1_1 { get; set; }
            public object P1_2 { get; set; }
            public object P1_3 { get; set; }
            public object P1_4 { get; set; }

            public StringBuilder P2_1 { get; set; }
            public StringBuilder P2_2 { get; set; }
            public StringBuilder P2_3 { get; set; }
            public StringBuilder P2_4 { get; set; }

            public Test()
            {
                P2_3 = new StringBuilder("P2_3");
            }
        }
        public static string Qualify(string name)
        {
            return "PropertyHost_Untyped." + name;
        }

        protected override void RegisterDeployments()
        {
            base.Register<object>()
                .Name(Qualify("a"))
                .Singleton(true)
                .Done();

            base.Register<StringBuilder>()
                .Name(Qualify("sb"))
                .Singleton(false)
                .CreatedBy.Constructor<string>(a => new StringBuilder(a))
                    .SetLiteral("i am an sb")
                .Done();

            base.Register<Test>()
                .Name(Qualify("obj"))
                .Singleton(true)
                .Property(x => x.P1_1)
                    .SetExpression("1+1")
                .Property(x => x.P1_2)
                    .SetUntypedObject("P1_2")
                .Property(x => x.P1_3)
                    .SetPlaceholder("${x}")
                .Property(x => x.P1_4)
                    .SetReference(Qualify("a"))

                .Property(x => x.P2_1)
                    .SetExpression("new System.Text.StringBuilder('hello')")
                .Property(x => x.P2_2)
                    .SetUntypedObject(new StringBuilder("P2_2"))
                .Property(x => x.P2_3)
                    .SetUntypedObject(null)
                .Property(x => x.P2_4)
                    .SetReference(Qualify("sb"))
                .Done();
        }

        protected override bool Include
        {
            get { return (UserContext == "property-config-1") && ALLOW; }
        }
        public static bool ALLOW = true;
    }
}
